package com.blockmeta.bbs.businesslibrary.arouter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blockmeta.bbs.businesslibrary.constant.Constant;

/**
 * @author AirThor
 * @date 2019/7/1.
 */
public class RouterHelper {
    public static Fragment fragment(String path){
        return (Fragment) ARouter.getInstance().build(path).navigation();
    }

    public static Fragment fragment(String path,String param1){
        return (Fragment) ARouter.getInstance().build(path).withString(Constant.ZERO,param1).navigation();
    }

    public static Fragment fragment(String path,String param1,String param2){
            return (Fragment) ARouter.getInstance().build(path).withString(Constant.ZERO,param1).withString(Constant.ONE,param2).navigation();
    }

    public static Postcard buildPath(String path){
        return ARouter.getInstance().build(path);
    }

    public static void startActivity(String path){
        startActivity(null,path);
    }

    public static void startActivity(Context context,String path){
        ARouter.getInstance().build(path).navigation(context);
    }
    public static void startActivity(Context context,String path,String param){
        ARouter.getInstance().build(path).withString(Constant.ZERO,param).navigation(context);
    }
    public static void startActivity(Context context,String path,int param){
            ARouter.getInstance().build(path).withInt(Constant.ZERO,param).navigation(context);
    }

    public static void startActivity(Context context,String path,String param,String param2){
        ARouter.getInstance().build(path).withString(Constant.ZERO,param).withString(Constant.ONE,param2).navigation(context);
    }

    public static void startActivity(Context context, String path, Parcelable object){
        ARouter.getInstance().build(path).withParcelable(Constant.ZERO, object).navigation(context);
    }

    public static void startActivityForResult(Activity activity, String path, int requestCode){
        ARouter.getInstance().build(path).navigation(activity, requestCode);
    }

    public static void startActivityForResult(Activity activity, String path, int requestCode, Bundle bundle){
        ARouter.getInstance().build(path).with(bundle).navigation(activity, requestCode);
    }

    @SuppressWarnings("unchecked")
    public static <T extends IProvider> T getProvider(String routPath){
        return (T) ARouter.getInstance().build(routPath).navigation();
    }
}
